package com.hitqz.robot.api.business.enums;

import com.hitqz.robot.api.common.dto.form.FormFieldConfigDto;

public enum RobotParamsFormFieldEnum {
    //传感器使能
    ULTRASONIC_ENABLE("ultrasonicEnable", "超声波避障使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),
    COLLISION_AVOIDANCE_ENABLED("collisionAvoidanceEnabled", "防碰撞使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),
    DROP_AVOIDANCE_ENABLED("dropAvoidanceEnabled", "防跌落使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),
    INFRARED_AVOIDANCE_ENABLED("infraredObstacleEnabled", "红外避障使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),
    SAFETY_AVOIDANCE_ENABLED("safetyRadarEnabled", "安全雷达避障使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),
    // [轮式]
    NAV_LIDAR_ENABLED("NavRadarEnabled", "激光雷达避障使能[全局]", "radio", "1", "[{\"value\":\"0\",\"label\":\"禁用\"},{\"value\":\"1\",\"label\":\"启用\"}]"),


    //传感器参数
    // [挂轨]
    FRONT_ULTRASONIC_TRIGGER_DISTANCE("frontUltrasonicTriggerDistance", "前超声波避障触发距离(mm)", "number", "300", null, 0, 2000),
    FRONT_ULTRASONIC_RELEASE_DISTANCE("frontUltrasonicReleaseDistance", "前超声波避障解除距离(mm)", "number", "400", null, 0, 2000),
    BACK_ULTRASONIC_TRIGGER_DISTANCE("backUltrasonicTriggerDistance", "后超声波避障触发距离(mm)", "number", "300", null, 0, 2000),
    BACK_ULTRASONIC_RELEASE_DISTANCE("backUltrasonicReleaseDistance", "后超声波避障解除距离(mm)", "number", "400", null, 0, 2000),
    CHARGER_IP("chargerIp", "充电站IP", "text", "", null),
    CHARGER_PORT("chargerPort", "充电站端口号", "number", "8080", null, 0, 65535),
    RELAY_IP("relayIp", "继电器IP", "text", "", null),
    RELAY_PORT("relayPort", "继电器端口号", "number", "8080", null, 0, 65535),


    //机器人本体参数
    ROBOT_SPEED("robotSpeed", "机器人自主运行速度(cm/s)", "number", "20", null, 20, 50),
    //[挂轨]
    TRACK_LOCATE_METHOD("trackLocateMethod", "定位方式", "radio", "rfid", "[{\"value\":\"mileage\",\"label\":\"里程计定位\"},{\"value\":\"rfid\",\"label\":\"rfid定位\"}]"),
    ROBOT_MILEAGE_CALIBRATION_FACTOR("robotMileageCalibrationFactor", "里程计校准系数", "number", "1000", null, 500, 1000),
    RFID_READER_POWER("rfidReaderPower", "RFID读取功率", "number", "27", null, 0, 10),

    //4串口转网口模块配置  一般用来读取传感器数值，这个模块配置成server，执行段建client去轮询[万华轮式]
    TAS_LAN_464_IP("tasLan464Ip", "464模块IP", "text", "", null),
    TAS_LAN_464_COM1_PORT("tasLan464Com1Port", "464模块COM1端口号", "number", "1", null, 0, 65535),
    TAS_LAN_464_COM1_NAME("tasLan464Com1Name", "464模块COM1名称", "text", "", null),
    TAS_LAN_464_COM1_MESSAGE_TEXT("tasLan464Com1MessageText", "464模块COM1报文[多条,隔开]", "text", "", null),
    TAS_LAN_464_COM2_PORT("tasLan464Com2Port", "464模块COM2端口号", "number", "2", null, 0, 65535),
    TAS_LAN_464_COM2_NAME("tasLan464Com2Name", "464模块COM2名称", "text", "", null),
    TAS_LAN_464_COM2_MESSAGE_TEXT("tasLan464Com2MessageText", "464模块COM2报文[多条,隔开]", "text", "", null),
    TAS_LAN_464_COM3_PORT("tasLan464Com3Port", "464模块COM3端口号", "number", "3", null, 0, 65535),
    TAS_LAN_464_COM3_NAME("tasLan464Com3Name", "464模块COM3名称", "text", "", null),
    TAS_LAN_464_COM3_MESSAGE_TEXT("tasLan464Com3MessageText", "464模块COM3报文[多条,隔开]", "text", "", null),
    TAS_LAN_464_COM4_PORT("tasLan464Com4Port", "464模块COM4端口号", "number", "4", null, 0, 65535),
    TAS_LAN_464_COM4_NAME("tasLan464Com4Name", "464模块COM4名称", "text", "", null),
    TAS_LAN_464_COM4_MESSAGE_TEXT("tasLan464Com4MessageText", "464模块COM4报文[多条,隔开]", "text", "", null),

    // M518R usb开门器配置
    M518R_COM_NAME("m518rComName", "M518R开门器串口名称", "text", "ttyUSB0", null),
    M518R_COM_OPEN_MESSAGE_TEXT("m518rOpenMessageText", "M518R开门报文", "text", "", null),
    M518R_COM_CLOSE_MESSAGE_TEXT("m518rCloseMessageText", "M518R关门报文", "text", "", null),


    // PLC 取油柜子
    PLC_WASTE_OIL("wasteOil", "废油量", "number", "", null),

    PLC_FET_OIL("fetOil", "取油量", "number", "", null)




    ;


    private final static String formName = "robot_params_config" ;       //所属动态表单名称
    private final String fieldName;      // 字段名称 (业务逻辑使用)
    private final String fieldLabel;     // 字段标签 (表单展示使用)
    private final String fieldType;      // 字段类型 (如 text, radio, checkbox)
    private final String defaultValue;   // 默认值
    private final String options;        // 选项 (JSON 字符串，针对 radio, select 等类型)
    private final Integer minValue;      // 最小值 (用于数值类型)
    private final Integer maxValue;      // 最大值 (用于数值类型)

    // 枚举构造函数
    RobotParamsFormFieldEnum(String fieldName, String fieldLabel, String fieldType, String defaultValue, String options) {
        this(fieldName, fieldLabel, fieldType, defaultValue, options, null, null);
    }

    RobotParamsFormFieldEnum(String fieldName, String fieldLabel, String fieldType, String defaultValue, String options, Integer minValue, Integer maxValue) {
        this.fieldName = fieldName;
        this.fieldLabel = fieldLabel;
        this.fieldType = fieldType;
        this.defaultValue = defaultValue;
        this.options = options;
        this.minValue = minValue;
        this.maxValue = maxValue;
    }

    public static RobotParamsFormFieldEnum fromFieldName(String fieldName) {
        for (RobotParamsFormFieldEnum fieldEnum : values()) {
            if (fieldEnum.getFieldName().equals(fieldName)) {
                return fieldEnum;
            }
        }
        return null;
    }

    // 生成 FormFieldConfigDto 的方法
    public FormFieldConfigDto toConfigDto() {
        return new FormFieldConfigDto(
                this.fieldName,
                this.fieldLabel,
                this.fieldType,
                this.defaultValue,
                this.defaultValue,  // 初始化当前值为默认值
                false,               // 是否必填
                this.minValue,
                this.maxValue,
                null,       // 正则表达式
                this.options
        );
    }

    // Getter 方法
    public String getFieldName() {
        return fieldName;
    }

    public String getFieldLabel() {
        return fieldLabel;
    }

    public String getFieldType() {
        return fieldType;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public String getOptions() {
        return options;
    }

    public Integer getMinValue() {
        return minValue;
    }

    public Integer getMaxValue() {
        return maxValue;
    }

    public String getFormName(){return formName;}
}